<?php
/**
 * @author yuanyitian
 * @date 2024/10/23 8:36
 * 自动取消超时未支付订单
 */
header("content-type:text/html;charset=utf8");
date_default_timezone_set("Asia/Shanghai");
set_time_limit(0);
$time=time();
$con = mysqli_connect('127.0.0.1:3306', 'www_skmymz_com', 'zC4tEAxCxkhbMKkp', 'luoping');
mysqli_query($con, "set names 'utf8'");
$order=mysqli_query($con,"select * from `order` where status=0");
$order=mysqli_fetch_all($order,true);
$ids=[];
for($i=0;$i<count($order);$i++){
    if(($order[$i]['create_time']+180)<$time){
        $ids[]=(int)$order[$i]['id'];
    }
}
if(!empty($ids)){
    $ids=implode(',',$ids);
    $res=mysqli_query($con,"update `order` set status=-1,cancel_time=$time,update_time=$time where id in ($ids)");
    echo "自动取消的执行结果为：$ids";
}

mysqli_close($con);

